package queue;

/**
 * @author chtw
 * @date 2020-09-05 16:48
 */
public class NotLoopQueue {

    private int front;
    private int rear;
    private int maxSize;
    private int[] arr;

    public NotLoopQueue(int maxSize) {
        this.front = this.rear = -1;
        this.maxSize = maxSize;
        this.arr = new int[maxSize];
    }

    public boolean push(int value) {
        if (this.rear == this.maxSize) {
            // 队列满
            return false;
        }
        this.arr[++rear] = value;
        return true;
    }

    public Integer pop() {
        // 队列空
        if (this.rear == this.front) {
            return null;
        }
        return this.arr[++front];
    }

    public void list() {
        // 队列空
        if (this.rear == this.front) {
            System.out.println("队列空~");
            return;
        }
        for (int i = this.front + 1; i <= this.rear; i++) {
            System.out.printf("arr[%d]=%d\n", i, this.arr[i]);
        }
    }
}
